import request from '@/utils/request'

/**
 *
 * @param {*} data
 */
export function usersList(data) { // 在职人员
  return request({
    url: 'system/user/queryUserList',
    method: 'post',
    data: data
  })
}

export function usersAllList(data) { // 含有离职人员
  return request({
    url: 'system/user/getAllStatusUser',
    method: 'post',
    data: data
  })
}
/**
 * type
 * @param {*} data
 */
export function depList(data) {
  return request({
    url: 'system/dept/queryDeptTree',
    method: 'post',
    data: data
  })
}

// 搜索部门
export function searchDept(data) {
  return request({
    url: 'system/dept/searchDept',
    method: 'post',
    data: data
  })
}
// 查询当前部门下人员个数
export function getDeptNum(data) {
  return request({
    url: 'system/dept/getDeptNumById',
    method: 'post',
    data: data
  })
}
// 查询离职人员
export function getQuitUsers(data) {
  return request({
    url: 'system/user/getQuitUsers',
    method: 'post',
    data: data
  })
}
// 获取权限范围内部门接口
export function adminStructuresSubIndex(data) {
  return request({
    url: 'system/dept/queryDeptByAuth',
    method: 'post',
    data: data
  })
}
// 获取权限范围内部门接口
export function getUserByDeptId(data) {
  return request({
    url: 'system/user/queryUserByDeptId',
    method: 'post',
    data: data
  })
}


// 部门下的员工
export function userListByStructid(data) {
  return request({
    url: 'admin/users/userListByStructid',
    method: 'post',
    data: data
  })
}

// 员工的导入导出
export function employeeDownloadExcelAPI(data) { // 下载模板
  return request({
    url: 'system/user/downloadUserExcelTemplate',
    method: 'post',
    data: data,
    responseType: 'blob'
  })
}
export function postDownloadExcelAPI(data) { // 部门下载模板
  return request({
    url: 'system/dept/downloadDeptExcelTemplate',
    method: 'post',
    data: data,
    responseType: 'blob'
  })
}

export function employeeExcelImport(data) { // 员工批量导入
  var param = new FormData()
  Object.keys(data).forEach(key => {
    param.append(key, data[key])
  })
  return request({
    url: 'system/user/uploadUser',
    method: 'post',
    data: param,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
export function postExcelImport(data) { // 部门批量导入
  var param = new FormData()
  Object.keys(data).forEach(key => {
    param.append(key, data[key])
  })
  return request({
    url: 'system/dept/deptsImport',
    method: 'post',
    data: param,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
/**
 * 查看错误数据接口(员工导入错误)
 * @param {*} data
 */
export function employeeDownImportErrorAPI(data) { // 员工错误数据
  return request({
    url: 'system/user/downloadStaffErrorReport',
    method: 'post',
    data: data,
    responseType: 'blob'
  })
}
export function postDownImportErrorAPI(data) { // 部门错误数据
  return request({
    url: 'system/dept/downloadStaffErrorReport',
    method: 'post',
    data: data,
    responseType: 'blob'
  })
}
// 员工导出
export function employeeExcelExport(data) {
  return request({
    url: 'system/user/userExport',
    method: 'post',
    data: data,
    responseType: 'blob'
  })
}
/**
 *
 * @param {*} data
 */
export const crmFileSaveUrl = process.env.BASE_API + 'file/upload'
export const crmFileSaveUrlOss = process.env.BASE_API + 'file/uploadOss'
export function crmFileSave(data) {
  var param = new FormData()
  Object.keys(data).forEach(key => {
    param.append(key, data[key])
  })
  return request({
    url: 'file/upload',
    method: 'post',
    data: param,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
export function crmFileOssSave(data, config) {
  var param = new FormData()
  Object.keys(data).forEach(key => {
    param.append(key, data[key])
  })
  return request(Object.assign({
    url: 'file/uploadOss',
    method: 'post',
    data: param,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }, config))
}

export function modalFileSave(data) {
  var param = new FormData()
  Object.keys(data).forEach(key => {
    param.append(key, data[key])
  })
  return request({
    url: 'file/uploadModalFile',
    method: 'post',
    data: param,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
export function getProgressPercent(data, config) {
  return request(Object.assign({
    url: 'file/getUploadOssProcess',
    method: 'post',
    data: data
  }, config))
}


export function crmFileFormDataSave(data) {
  return request({
    url: 'file/upload',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 附件列表
export function crmFileIndex(data) {
  return request({
    url: 'file/queryByBatchId',
    method: 'post',
    data: data
  })
}

// 功能下的附件列表
export function getModalFiles(data) {
  return request({
    url: 'file/queryModalFiles',
    method: 'post',
    data: data
  })
}

/** 暂时客户管理里面也有 */
// 附件删除接口
export function crmFileDelete(data) {
  return request({
    url: 'file/removeById',
    method: 'post',
    data: data
  })
}

export function modalFileDelete(data) {
  return request({
    url: 'file/removeModalFileById',
    method: 'post',
    data: data
  })
}

// 附件重命名
export function crmFileUpdate(data) {
  return request({
    url: 'file/renameFileById',
    method: 'post',
    data: data
  })
}

// crm 自定义字段的添加
/**
 *
 * @param {*} data
 */
export function filedGetField(data) {
  return request({
    url: 'field/queryField',
    method: 'post',
    data: data
  })
}

// 权限数据返回
export function adminIndexAuthList(data) {
  return request({
    url: 'system/role/auth',
    method: 'post',
    data: data
  })
}
